﻿using System;
using Microsoft.AspNetCore.Mvc;
using PM.Bussiness.System;
using PM.Model.ConfigModel;
using PM.Helper;

namespace PM.Controllers
{
    /// <summary>
    /// 自动生成实体类
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class SystemController : Controller{
        private EntityBLL bll = new EntityBLL();

        #region 生成实体类
        /// <summary>
        /// 生成实体类
        /// </summary>
        /// <param name="entityName"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Entity/Create")]
        public JsonResult CreateEntity(string entityName)
        {
            return Json(bll.CreateEntity(entityName, BaseConfigModel.ContentRootPath));
        }
        #endregion

        #region Token
        /// <summary>
        /// 模拟登录，获取JWT
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("Token")]
        public JsonResult GetJWTStr()
        {
            TokenModel tm = new TokenModel(){
                Uid = "5",
                Role="Admin",
                Dept ="1",
                TokenType ="Web"
            };
            string ret = "Bearer "+JwtHelper.IssueJWT(tm);
            return Json(ret);
        }
        #endregion

        #region 测试接口是否畅通
        /// <summary>
        /// 测试接口是否通畅
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("Test")]
        public JsonResult Test()
        {
            var js = new
            {
                recode = 1
            };

            return Json(js);
        }
        #endregion

        #region 检查更新
        /// <summary>
        /// 检查更新
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("CheckUpdate")]
        public JsonResult CheckUpdate()
        {
            int newVera= Convert.ToInt32(BaseConfigModel.Configuration["AppVer"]);
            string url = BaseConfigModel.Configuration["AppPath"];
            bool isupdate = Convert.ToBoolean(BaseConfigModel.Configuration["isupdate"]);
            return Json(new
            {
                ver = newVera,
                url = url,
                isupdate= isupdate
            });
        }
        #endregion
    }

}